// pages/student/watch-record/watch-record.js
import { courses } from '../../../utils/mockData.js'

Page({
  data: {
    records: [],
    loading: true
  },
  onLoad() {
    this.loadRecords()
  },
  loadRecords() {
    wx.showLoading({ title: '加载中...' })
    // 模拟加载观看记录
    setTimeout(() => {
      const records = courses.map((course, index) => ({
        id: index + 1,
        course: course,
        watchTime: Math.floor(Math.random() * 120) + 30, // 30-150分钟
        lastWatch: new Date(Date.now() - Math.random() * 7 * 24 * 60 * 60 * 1000).toLocaleDateString(),
        progress: Math.floor(Math.random() * 100)
      }))
      
      this.setData({
        records: records.slice(0, 5),
        loading: false
      })
      wx.hideLoading()
    }, 500)
  },
  goToCourseDetail(e) {
    const id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: `/pages/student/course-detail/course-detail?id=${id}`
    })
  },
  continueWatch(e) {
    const id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: `/pages/student/live-room/live-room?courseId=${id}`
    })
  }
})
